package name.yzhu.index;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.List;

import org.apache.commons.io.IOUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class StopWordsHandler {
	private static final Log LOG = LogFactory.getLog(StopWordsHandler.class);
	
//	private static String stopWordsList[] ={"的", "我们","要","自己","之","将","“","”","，","（","）","后","应","到","某","后","个","是","位","新","一","两","在","中","或","有","更","好",""};//常用停用词
	private static List<String> stopWordsList = null;
	private static StopWordsHandler handle = new StopWordsHandler();

	private StopWordsHandler(){
	}

	public static StopWordsHandler getInstance() {
		return handle;
	}

	public static StopWordsHandler getInstance(String path) throws IOException {
		return getInstance(new File(path));
	}

	public static StopWordsHandler getInstance(File file) throws IOException {
		try {
			stopWordsList = IOUtils.readLines(new FileInputStream(file), 
					name.yzhu.common.Constant.CHARSET_UTF_8);
			return handle;
		}  catch (IOException e) {
			LOG.error(file.getAbsolutePath(), e);
			throw e;
		}
	}

	public boolean IsStopWord(String word)	{
		for(String w : stopWordsList)	{
			if(word.equalsIgnoreCase(w))
				return true;
		}
		return false;
	}
}
